// 属性管理相关的接口函数

// 0.引入异步对象
import request from '@/utils/request';
import type { attrInfoModel, attrListModel } from './model/attrModel'
import type { categoryIdsModel } from './model/categorySelectorModel'

// 1.使用枚举来存储接口地址
enum Api {
  getAttrListDataApi = '/admin/product/attrInfoList',
  saveAttrInfoApi = '/admin/product/saveAttrInfo',
  deleteAttrInfoApi = '/admin/product/deleteAttr'
}
// 定义接口函数并导出

// 2.根据一二三级导航ID 来获取属性列表
export const reqGetAttrListData = ({ category1Id, category2Id, category3Id }: categoryIdsModel) => {
  return request.get<any, attrListModel>(`${Api.getAttrListDataApi}/${category1Id}/${category2Id}/${category3Id}`)
}

// 3.添加或者更新属性
export const reqAddOrUpdateAttrInfo = (attrInfo: attrInfoModel) => {
  return request.post<any, null>(Api.saveAttrInfoApi, attrInfo)
}

// 4.删除属性
export const reqDeleteAttrInfo = (id: number) => {
  return request.delete<any, any>(Api.deleteAttrInfoApi + `/${id}`)
}
